package com.example.demo.mapper;

import com.example.demo.entity.DTO.FosterDTO;
import com.example.demo.entity.Foster;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 寄养表 Mapper 接口
 * </p>
 *
 * @author Mr.sdy
 * @since 2024-06-05
 */
@Mapper
public interface FosterMapper extends BaseMapper<Foster> {
    @Insert("INSERT INTO foster(user_id,pet_id,start_time,end_time,create_time) VALUES (#{userId},#{petId},#{startTime},#{endTime},now())")
    int insert(Foster foster);

    /**
     * 查询该用户所有寄养信息
     * @param userId
     * @return
     */
    @Select("SELECT t1.pet_name,t1.pet_sex,t1.pet_age,t1.pet_img,t1.pet_info,t2.start_time,t2.end_time \n" +
            "FROM pet t1 \n" +
            "INNER JOIN foster t2 \n" +
            "on t1.pet_id = t2.pet_id \n" +
            "WHERE t2.user_id=1")
    List<FosterDTO> selectFostersByUserId(Integer userId);
}
